<?php

namespace App\Controller\Web;

use App\Base\BaseConfig;
use App\Base\BaseController4Web;
use App\Entity\ArtCategory;
use App\Model\ArtCategoryModel;
use App\Model\ArtModel;
use App\Model\BannerModel;
use App\Project\ZhengHuaModel;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;

class IndexController extends BaseController4Web
{
    /**
     * @route("/undefined",name="indexundefined")
     */
    function indexundefined ()
    {
        return $this->index();
    }

    /**
     * @route("/",name="index")
     */
    public function index(){
        return $this->redirectToRoute("AdminLogin");
        die;
        $this->initData();
        $this->data["headTab"] = "index";

        //banner
        $BannerModel = new BannerModel($this->getDoctrine());
        $data = $BannerModel->get4Index();
        $this->data["banner"] = $data;

        $ArtCategoryModel = new ArtCategoryModel($this->getDoctrine());
        //获取资讯的首页栏目
        $data_list_zx = $ArtCategoryModel->getIndexCat("ZIXUN",5);
        $this->data["list_zx"] = $data_list_zx;
        //获取资料的首页栏目
        $data_list_zl = $ArtCategoryModel->getIndexCat("ZILIAO",6);
        $this->data["list_zl"] = $data_list_zl;
        //获取动态的首页栏目
        $data_list_dt = $ArtCategoryModel->getIndexCat("DONGTAI",6);
        $this->data["list_dt"] = $data_list_dt;


        return $this->render("Web/index.html.twig", $this->data);

    }

    /**
     * @route("/article",name="article")
     */
    public function article(){
        $this->initData();
        $this->data["headTab"] = "zixun";




        return $this->render("Web/article.html.twig", $this->data);
    }

    /**
     * @route("/files",name="files")
     */
    public function files(){
        $this->initData();
        $this->data["headTab"] = "ziliao";

        $ArtCategoryModel = new ArtCategoryModel($this->getDoctrine());
        //获取申论的子栏目
        $data_list_sl = $ArtCategoryModel->getSons(BaseConfig::__CAT_SHENLUN__);
        $this->data["list_sl"] = $data_list_sl;
        //获取行测的子栏目
        $data_list_xc = $ArtCategoryModel->getSons(BaseConfig::__CAT_XINGCE__);
        $this->data["list_xc"] = $data_list_xc;
        //获取公安的子栏目
        $data_list_ga = $ArtCategoryModel->getSons(BaseConfig::__CAT_GONGAN__);
        $this->data["list_ga"] = $data_list_ga;
        //获取时政的子栏目
        $data_list_sz = $ArtCategoryModel->getSons(BaseConfig::__CAT_SHIZHENG__);
        $this->data["list_sz"] = $data_list_sz;
        //获取面试的子栏目
        $data_list_ms = $ArtCategoryModel->getSons(BaseConfig::__CAT_MIANSHI__);
        $this->data["list_ms"] = $data_list_ms;

        //侧边栏
        //获取面试的子栏目
        $data_list_stxz = $ArtCategoryModel->getSons(BaseConfig::__CAT_SHITIXIAZAI__);
        $this->data["list_stxz"] = $data_list_stxz;

//        $this->data["id_stxz_sl"] = BaseConfig::__CAT_SHITIXIAZAI_SL__;
//        $this->data["id_stxz_xc"] = BaseConfig::__CAT_SHITIXIAZAI_XC__;

        return $this->render("Web/file.html.twig", $this->data);
    }

    /**
     * @route("/class",name="class")
     */
    public function classes(){
        $this->initData();
        $ArtCategoryModel = new ArtCategoryModel($this->getDoctrine());
        $cat = $ArtCategoryModel->getById(BaseConfig::__CAT_KECHENG__);
        if (!$page = $this->getParamRequired("page")) {$page = 1;}
        if (!$keywords = $this->getParamRequired("keywords")) {$keywords="";}
        $this->initData();
        $this->data["headTab"] = strtolower($cat->getLink());

        $ArtModel = new ArtModel($this->getDoctrine());
        $data = $ArtModel->getCatListData($cat->getId(),$page-1,13,$keywords);
        $this->data["data"] = $data;
        $this->data["page"] = $this->creatPage($this->generateUrl("class"),$data["total"],13);
        $this->data["keywords"] = $keywords;

        return $this->render("Web/class.html.twig", $this->data);
    }

    /**
     * @route("/news",name="news")
     */
    public function news(){
        $this->initData();
        $this->data["headTab"] = "dongtai";
        return $this->render("Web/news.html.twig", $this->data);
    }


    /**
     * @route("/article_cat_list/{id}",name="articleCatList")
     */
    public function articleCatList(ArtCategory $cat){
        if (!$page = $this->getParamRequired("page")) {$page = 1;}
        if (!$keywords = $this->getParamRequired("keywords")) {$keywords="";}
        $this->initData();
        $this->data["headTab"] = strtolower($cat->getLink());

        $ArtModel = new ArtModel($this->getDoctrine());
        $data = $ArtModel->getCatListData($cat->getId(),$page-1,10,$keywords);
        $this->data["data"] = $data;
        $this->data["page"] = $this->creatPage($this->generateUrl("articleCatList",["id"=>$cat->getId()]),$data["total"],10);
        $this->data["keywords"] = $keywords;
        return $this->render("Web/article_cat_list.html.twig", $this->data);
    }

    /**
     * @route("/article_pic_list/{id}",name="articlePicList")
     */
    public function articlePicList(ArtCategory $cat){
        if (!$page = $this->getParamRequired("page")) {$page = 1;}
        if (!$keywords = $this->getParamRequired("keywords")) {$keywords="";}
        $this->initData();
        $this->data["headTab"] = strtolower($cat->getLink());

        $ArtModel = new ArtModel($this->getDoctrine());
        $data = $ArtModel->getCatListData($cat->getId(),$page-1,10,$keywords);
        $this->data["data"] = $data;
        $this->data["page"] = $this->creatPage($this->generateUrl("articleCatList",["id"=>$cat->getId()]),$data["total"],10);
        $this->data["keywords"] = $keywords;
        return $this->render("Web/article_cat_list.html.twig", $this->data);
    }
}
